package router

import (
	"demo/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

func Router() *gin.Engine {
	router := gin.Default()

	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	router.GET("/index", service.Hello)
	router.GET("/test", service.TestApi)

	err := router.Run(viper.GetString("server.httpPort"))
	if err != nil {
		fmt.Println("gin启动失败", err)
		return nil
	}
	return router
}
